package com.wtwd.campus.receiver;

import com.alibaba.fastjson.JSONObject;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.MqGeneralSwitchResult;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.service.WebRemoteService;
import com.wtwd.campus.service.entity.DeviceLog;

public class SetSilentShutDownReceiver implements Receiver {
    @Override
    public String parseMessage(String data) {
        //*TJ,MEID,V4, GJSILENT,HHMMSS, FLAG,Date(日月年）,tracker_status#
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber=split[4];
        String flag=split[5];//1打开，0关闭；
        String deviceDate=split[6];//设备状态
        String deviceStatus=split[7];//设备状态
        MqGeneralSwitchResult mqGeneralSwitchResult = new MqGeneralSwitchResult();
        mqGeneralSwitchResult.setImei(imei);
        mqGeneralSwitchResult.setDeviceTime(commandNumber);
        mqGeneralSwitchResult.setCommandNumber(commandNumber);
        mqGeneralSwitchResult.setResult(Integer.parseInt(flag));
        mqGeneralSwitchResult.setDeviceStatus(deviceStatus);
        mqGeneralSwitchResult.setDeviceDate(deviceDate);
        InjectFeignService.getIrmFeignClientService().setShutDownSilent(mqGeneralSwitchResult);
        //存储设备接收日志
        DeviceLog deviceLog = new DeviceLog();
        deviceLog.setSendUser(Constants.DEVICE_USER);
        deviceLog.setImei(imei);
        deviceLog.setBigType(messageType);
        deviceLog.setType(type);
        JSONObject contant = new JSONObject();
        contant.put("设备号", imei);
        contant.put("1打开，0关闭；",flag);
        contant.put("设备日期",deviceDate);
        contant.put("设备状态",deviceStatus);
        deviceLog.setCmd(contant.toJSONString());
        deviceLog.setSendTime(System.currentTimeMillis());
        deviceLog.setCommandNumber(commandNumber);
        deviceLog.setState(1);
        WebRemoteService webRemoteService = InjectFeignService.getWebRemoteService();
        webRemoteService.addDeviceLog(deviceLog);
        return imei;
    }
}
